import { Component } from '@angular/core';
import {  NavController, NavParams ,ViewController} from 'ionic-angular';
import { RestProvider } from '../../../providers/rest/rest';
import { TextToSpeech } from '@ionic-native/text-to-speech';
/**
 * Generated class for the GetweatherPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-getweather',
  templateUrl: 'getweather.html',
})
export class GetweatherPage {
  public text='';
  constructor(public navCtrl: NavController,
     public navParams: NavParams,
      public rest: RestProvider, 
      public viewCtrl:ViewController,
      public tts: TextToSpeech) {
    this.getWeather();
  }
  dismiss(){
    this.viewCtrl.dismiss();
  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad GetweatherPage');
  }
  textToPage(text){
    this.tts.speak(text)
    .then(() => console.log('Success'))
    .catch((reason: any) => console.log(reason));
  }
  getWeather(){
            this.rest.weather('西安', '陕西').subscribe(
            (res:any) => {
                console.log(res);
                let data=res.result[0];
                let city=data.city;
                let week=data.week;
                let weather=data.weather;
                let temperature=data.temperature;
                this.text=`${city}${week}${weather}${temperature}`;
                this.textToPage(this.text)
            },
            (err) => {
                console.log(err);
            }
        );
  }

}
